<template>
  <div class="department" id="department">
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav_left">
          <el-radio-group
            v-model="radio"
            size="small"
            @change="modelType($event)"
          >
            <el-radio-button label="待办"></el-radio-button>
            <el-radio-button label="已办"></el-radio-button>
            <!-- #2b5a9d -->
          </el-radio-group>
        </div>
        <!-- 顶部按钮 -->
        <div class="print">
          <div class="printTable">
            <el-button
              type="primary"
              icon="el-icon-refresh"
              size="small"
              @click="yj_searchForm(getList)"
            ></el-button>
            <el-button
              type="primary"
              icon="el-icon-circle-plus-outline"
              size="small"
              v-if="getList.modelType == '0' && yj_add == true"
              @click="edit('新增')"
              >新增</el-button
            >
            <!-- 签发中,待签收,执行中,待复核,已结束-->
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="small"
              v-if="getList.modelType == '0' && yj_edit == true"
              @click="edit('编辑')"
              >编辑</el-button
            >
            <el-button
              type="primary"
              icon="el-icon-circle-check"
              size="small"
              v-if="getList.modelType == '0' && yj_send == true"
              @click="SubmitText(fId)"
              >签发</el-button
            >
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="small"
              v-if="getList.modelType == '0' && yj_receive == true"
              @click="edit('签收')"
              >签收</el-button
            >
            <el-button
              type="primary"
              icon="el-icon-delete"
              size="small"
              v-if="getList.modelType == '0' && yj_delete == true"
              @click="rowDelete(fId)"
              >删除</el-button
            >
          </div>
        </div>
      </div>

      <!-- 表格 -->
      <div class="text_table">
        <tableData
          :height="navigatepageNums > 1 ? 'calc(100% - 50px)' : '100%'"
          :config="table_config"
          :dataList="tableData"
          :loading="loading"
          @selection-change="selectionChange"
          @sort-change="sortChange"
          @click-change="rowChange"
          @ClickOnLine="yj_viewForm"
          :page="getList.page"
          :pageSize="getList.pageSize"
        />
        <pagination
          v-if="navigatepageNums > 1"
          :info="queryCriteriaData"
          :treelength="treelength"
          :total="queryCriteriaData.total"
          :pageNum.sync="getList.page"
          :limit.sync="getList.pageSize"
          @pagination="yj_searchForm(getList)"
        />
      </div>
      <!--班组首件信息弹框-->
      <div class="Control-1 mechanism_dialogS closure">
        <el-dialog
          :title="dialogTitle"
          :modal-append-to-body="false"
          v-dialogDrag
          :visible.sync="dialogEditVisible"
          v-loading="loadingEditDialog"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
        >
          <div
            class="dialogBody common"
            :style="{ height: '650px' }"
            style="overflow: hidden"
          >
            <div style="overflow-y: auto; margin-bottom: 20px; height: 100%">
              <div class="baseTitle">工作指令信息</div>
              <div class="publicForm" style="height: 285px; overflow-y: auto">
                <publicForm
                  ref="publicForm"
                  lableWidth="110px"
                  :formObj="FromShow"
                  :formData="formData"
                  :timestamp="formData.fOrderfile"
                  :fileList="fSourcefileList"
                  @selectChange="selectChange"
                  @inputChange="inputChange"
                  @delteFile="delteFile"
                  @inputFocus="inputFocus"
                >
                </publicForm>
              </div>
              <div class="baseTitle" v-if="Sign == '签收' || Sign == '查看'">
                指令签收
              </div>
              <div
                class="publicForm"
                style="height: 70px; overflow-y: auto"
                v-if="Sign == '签收' || Sign == '查看'"
              >
                <publicForm
                  ref="publicForm0"
                  lableWidth="110px"
                  :formObj="putAway"
                  :formData="formData"
                  @selectChange="selectChange"
                  @inputChange="inputChange"
                >
                </publicForm>
              </div>
              <div style="height: 50px"></div>
            </div>
          </div>
          <div class="newlyAdded_btn" v-if="btnShow">
            <el-button
              type="primary"
              @click="yj_saveForm(1)"
              v-if="Sign == '签收'"
              >保存</el-button
            >
            <el-button type="primary" @click="yj_saveForm(0)" v-else
              >保存</el-button
            >
            <el-button type="warning" @click="dialogEditVisible = false"
              >关闭</el-button
            >
          </div>
        </el-dialog>
      </div>
      <!--机构树弹框-->
      <div class="Control-1 mechanism_dialogS closure" id="department1">
        <el-dialog
          title="请选择机构树"
          :modal-append-to-body="false"
          v-dialogDrag
          :visible.sync="dialogEditVisibles"
          v-loading="loadingEditDialogs"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
        >
          <div
            class="dialogBody common"
            :style="{ height: '450px' }"
            style="overflow: hidden"
          >
            <div class="text_table" style="overflow: auto">
              <el-table
                @row-click="getRowInfos"
                ref="multipleTable"
                height="100%"
                :data="treeData"
                style="width: 100%"
                border
                default-expand-all
                :tree-props="{
                  children: 'children',
                  hasChildren: 'hasChildren',
                }"
                row-key="fCompanyid"
                highlight-current-row
                @current-change="rowChangeColor"
                stripe
              >
                <el-table-column
                  fixed
                  type="index"
                  label="序号"
                  width="50"
                  align="center"
                ></el-table-column>
                <el-table-column
                  prop="fFullname"
                  label="机构名称"
                ></el-table-column>
                <el-table-column
                  prop="fEncode"
                  label="机构编码"
                  width="100"
                  align="center"
                ></el-table-column>
                <el-table-column
                  prop="fShortname"
                  label="机构简称"
                  align="center"
                >
                </el-table-column>
                <el-table-column
                  prop="fNature"
                  label="机构性质"
                  width="100"
                  align="center"
                >
                </el-table-column>
              </el-table>
            </div>
          </div>

          <div class="newlyAdded_btn" v-if="btnShow">
            <el-button type="primary" @click="yj_saveForm(3)">保存</el-button>
            <el-button type="warning" @click="dialogEditVisibles = false">
              关闭
            </el-button>
          </div>
        </el-dialog>
      </div>
      <!-- 根据组织机构树选人 -->
      <div class="Control-1 mechanism_dialogS closure">
        <el-dialog
          :title="candidate"
          :modal-append-to-body="false"
          v-dialogDrag
          :visible.sync="dialogEditVisibleTree"
          v-loading="loadingEditDialogTree"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
        >
          <div
            class="dialogBody common"
            :style="{ height: '650px' }"
            style="overflow: hidden; width: 100%"
          >
            <div style="margin-bottom: 20px; height: 100%; width: 100%">
              <div
                class="publicForm addMemberCheckBox"
                style="height: calc(100% - 40px); overflow-y: auto; width: 100%"
              >
                <div class="addMemberCheckTree">
                  <div class="companyBox">
                    <el-tree
                      :data="companyInfo"
                      :props="defaultProps"
                      @node-click="selectCompany"
                      :highlight-current="highlightBd"
                    ></el-tree>
                  </div>
                  <div class="departmentBox">
                    <div
                      class="departmentTitle"
                      v-for="(item, index) in departmentList"
                      :key="index"
                      @click="seletDepartment(item, index)"
                    >
                      <a
                        href="javascript:;"
                        :class="num === item.fDepartmentId ? 'activetext' : ''"
                        :title="item.fShortName"
                      >
                        {{ item.fShortName }}</a
                      >
                    </div>
                  </div>
                </div>

                <div class="addMemberCheckLeft">
                  <el-checkbox-group
                    v-model="checkboxGroup1"
                    @change="selectRealname($event, personList)"
                  >
                    <el-checkbox-button
                      v-for="item in personList"
                      :label="item.fUserid"
                      :key="item.fUserid"
                      :value="item.fRealname"
                    >
                      <div class="addMemberCheck">
                        <div class="MemberIcon">
                          <!--  -->
                          <!-- -->
                          <img :src="item.fGender == 0 ? girls : boys" alt="" />
                        </div>
                        <div class="MemberDetailInfos">
                          <div class="name">{{ item.fRealname }}</div>
                          <div class="hostName">{{ item.fDepartmentName }}</div>
                          <div class="hostName">{{ item.fAccount }}</div>
                        </div>
                      </div>
                    </el-checkbox-button>
                  </el-checkbox-group>
                </div>

                <div class="selectPerson">
                  <div class="selectPersonTitle">
                    已选人员（{{ newData.length }}人）
                  </div>
                  <div class="selectPersonData">
                    <div
                      class="selectPersonDataBox"
                      v-for="item in newData"
                      :label="item.fRealname"
                      :key="item.fRealname"
                    >
                      <div class="MemberIcon">
                        <img :src="item.fGender == 0 ? girls : boys" alt="" />
                      </div>
                      <div class="MemberDetailInfo1">
                        <div class="name">{{ item.fRealname }}</div>
                        <div class="hostName">{{ item.fDepartmentName }}</div>
                        <div class="hostName">{{ item.fAccount }}</div>
                      </div>
                      <div
                        class="deleteUser"
                        @click="deteleUser(item.fUserid)"
                      ></div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="newlyAdded_btn" v-if="btnShow">
            <el-button type="primary" @click="submitMember()">保存</el-button>
            <el-button type="warning" @click="dialogEditVisibleTree = false"
              >关闭</el-button
            >
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>
<script>
import {
  getWorkOrderExecutionReportPageLists, //列表
  getWorkOrderExecutionReportByFid, //详情
  saveWorkOrder, //保存
  saveWorkOrderBySign, //签收
  deleteWorkOrderExecutionReport, //删除
  commitWorkOrderExecutionReport, //签发
  getUserCompanyTreeList, //树结构
  getBaseDepartmentUser, //查人员
} from "@/api/request.js";
import TableData from "@/components/stationProductionPage/pitchManage/dyMonitorManage/el-tables"; //主页面列表
import Pagination from "@/components/public/el-pagination"; //主页面分页
import publicForm from "@/components/public/el-form.vue"; //弹框form
import formJs from "../regexDetail.js"; //新增弹框配置项
// import tree from "@/components/public/el-trees"; //左侧机构树

export default {
  inject: ["reload"],
  name: "distributeText",
  data() {
    return {
      name: "distributeText",
      // 分页
      navigatepageNums: null, //是否显示分页
      queryCriteriaData: {},
      // 分页
      yj_add: null,
      yj_edit: null,
      yj_delete: null,
      yj_send: null,
      yj_receive: null,

      radio: "待办",

      // 列表
      getList: {
        fCompanyid: "", // 左侧选中组织机构id
        page: 1, //页码
        pageSize: 20, //每页条数
        userId: "", // 查询待办或已办时传 列表页查询不传
        modelType: "", // 0代办 1已办 2表示列表页查询
        fQualitygridclass: "", // 上方查询条件质量网格
        fQualitygridtype: "", // 上方查询条件工程网格
        keyWord: "", // 责任人
      },
      fId: null, //当前行数据fId
      row: { fstatus: "" }, //选中行
      loading: false, //列表转载
      table_config: formJs.table_configText,
      tableData: [], //表格列表数据列表
      // 列表

      // 弹框
      Sign: "",
      timeYMD: null, //当前日期
      btnShow: true,
      dialogTitle: "",
      loadingEditDialog: false, //弹框loading
      dialogEditVisible: false, //新增弹框是否显示
      FromShow: null, //下发
      FromShowText: formJs.FromShowText, //下发---编辑
      FromShowLook: formJs.FromShowLook, //下发---查看

      putAway: null, //签收
      putAwayText: formJs.putAwayText, //签收---编辑
      putAwayLook: formJs.putAwayLook, //签收---查看

      formData: formJs.formData,
      CcpeoplesUserList: [], //复选人员框
      recordfiles: [], //删除文件
      fSourcefileList: [],
      saveData: {},
      getUserInitialList: [], //指定签收人初始列表
      getUserList: [],
      // 机构树弹框
      loadingEditDialogs: false, //弹框loading
      dialogEditVisibles: false, //新增弹框是否显示
      showTreeData: null,
      companyTree: "", //所有数据
      checkData: [], //树状图默认选中id
      treeData: [], //左侧树状图数据
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      treeText: {
        companyId: null,
        userId: null,
      },
      // 机构树弹框
      // 树选人
      dialogEditVisibleTree: false,
      loadingEditDialogTree: false,
      companyInfo: [], //公司树信息
      highlightBd: true,
      // defaultProps: {
      //   children: "children",
      //   label: "fShortname",
      // },
      departmentList: [], //部门
      num: null,
      personList: [], //人员列表新增
      checkboxGroup1: [],
      boys: require("@/assets/img/organization/boys.png"),
      girls: require("@/assets/img/organization/girls.png"),
      newData: [],
      // treeText: {
      //   companyId: null,
      //   userId: null,
      // },
      propText: null,
      candidate: null,
      allUserInfo: [],
      userList: [],
      userListId: [],

      // 树选人
      // 弹框

      userInfo: {}, //登录用户
    };
  },
  components: {
    TableData, //主页面列表
    Pagination, //分页
    publicForm, //表单
    // tree, //机构树
  },
  created() {},
  mounted() {
    this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));
    console.log("userInfo", this.userInfo);
    this.getList = {
      // fCompanyid: this.userInfo.companyId, // 左侧选中组织机构id
      fCompanyid: "", // 左侧选中组织机构id
      userId: this.userInfo.userId, // 查询待办或已办时传 列表页查询不传
      page: 1, //页码
      pageSize: 20, //每页条数
      modelType: "0", // 0代办 1已办 不传或传空 表示列表页查询
      fQualitygridclass: "", // 上方查询条件质量网格
      fQualitygridtype: "", // 上方查询条件工程网格
      keyWord: "", // 责任人
    };
    this.getHeight();
    this.getData();
    this.yj_searchForm(this.getList);
    this.btnRole(this.name);
  },
  methods: {
    btnRole(name) {
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("yjSmart-ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        this.yj_add = btnStr.includes("yj_add");
        this.yj_edit = btnStr.includes("yj_edit");
        this.yj_delete = btnStr.includes("yj_delete");
        this.yj_send = btnStr.includes("yj_send");
        this.yj_receive = btnStr.includes("yj_receive");
      } else {
        this.yj_add = true;
        this.yj_edit = true;
        this.yj_delete = true;
        this.yj_send = true;
        this.yj_receive = true;
      }
    },
    modelType(e) {
      this.fId = "";
      this.row = "";
      if (e == "待办") {
        this.getList.modelType = "0";
        this.getList.userId = this.userInfo.userId;
      } else {
        this.getList.modelType = "1";
        this.getList.userId = this.userInfo.userId;
      }
      this.yj_searchForm(this.getList);
    },
    // 获取列表数据
    yj_searchForm(id) {
      this.row = { fstatus: "" }; //选中行
      this.loading = true;
      getWorkOrderExecutionReportPageLists(id)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.loading = false;
            that.tableData = res.data.pageInfo.list;
            that.queryCriteriaData = res.data.pageInfo;
            that.navigatepageNums =
              that.queryCriteriaData.navigatepageNums.length;
          } else {
            this.$message.error("列表", res.msg);
            this.loading = false;
          }
        })
        .catch(() => {
          this.loading = false;
        });
    },
    edit(title) {
      this.Sign = title;
      this.dialogTitle = title;
      this.recordfiles = [];
      this.fSourcefileList = [];
      this.btnShow = true;
      this.FromShow = this.FromShowText;
      if (title == "新增") {
        this.FromShow[10].options = [];
        this.newData = [];
        this.checkboxGroup1 = [];
        var fOrderfile = "fOrderfile" + new Date().valueOf();
        this.formData = {
          fId: "", //传入表示修改 不传表示新增
          userId: this.userInfo.userId, //当前登录人id
          userName: this.userInfo.realName, // 当前登录人名称
          fProjectname: this.userInfo.projectName, // 当前登录人项目名称
          fProjectid: this.userInfo.projectId, // 当前登录人项目ID
          fCompanyname: this.userInfo.companyName, // 当前登录人标段名称
          fCompanyid: this.userInfo.companyId, // 当前登录人标段ID
          fOrdertype: "", // 指令单类型
          fOrderissuingname: this.userInfo.companyName, // 指令单签发单位
          fOrderissuingid: this.userInfo.companyId, // 指令单签发单位id
          fOrdernumber: "", // 指令单编号  有填  无"/"
          fOrderreceiptname: "", // 指令单签收单位------弹出框选机构树
          fOrderreceiptid: "", // 指令单签收单位id
          fIssuername: this.userInfo.realName, // 签发人姓名
          fIssuerid: this.userInfo.userId, // 签发人id
          fIssuerdates: this.timeYMD, // 签发日期
          fQualitygridclass: "", // 涉及质量网格
          fQualitygridtype: "", // 涉及工程质量网格
          fOrederdetail: "", // 工作指令内容
          fReplydates: this.timeYMD, // 要求回复日期
          fOrderfile: fOrderfile, // 附件资料
          fSignsubname: "", // 指定签收人姓名----根据机构树  调人员列表
          fSignsubid: "", // 指定签收人id
          // fCcpeoples: [], //抄送人姓名集合
          // fCcpeopleids: [], //抄送人id集合
          fCcpeoples: "", //抄送人姓名集合
          fCcpeopleids: [], //抄送人id集合
          fInformantname: this.userInfo.realName, // 填报人姓名
          fInformantid: this.userInfo.userId, // 填报人id
          fInformantdates: this.timeYMD, // 填报日期
          recordfiles: [], // 删除文件id集合
        };
        this.dialogEditVisible = true;
      } else if (title == "签收") {
        if (this.fId == "" || this.fId == null) {
          this.$message.error("请先选择需要签收的数据");
        } else {
          if (this.row.fstatus == "待签收") {
            this.FromShow = this.FromShowLook;
            this.putAway = this.putAwayText;
            this.loadingEditDialog = true; //弹框loading
            this.dialogEditVisible = true;
            this.getConcrete(this.fId);
          } else {
            this.$message.error("请选择信息状态为‘待签收’的数据");
          }
        }
      } else if (title == "编辑") {
        if (this.fId == "" || this.fId == null) {
          this.$message.error("请先选择需要编辑的数据");
        } else {
          if (this.row.fstatus == "签发中") {
            this.loadingEditDialog = true; //弹框loading
            this.dialogEditVisible = true;
            this.getConcrete(this.fId);
          } else {
            this.$message.error("请选择信息状态为‘签发中’的数据");
          }
        }
      }
    },
    // 获取详情
    getConcrete(id) {
      getWorkOrderExecutionReportByFid({ fId: id })
        .then((res) => {
          if (res.errcode == 0) {
            this.loadingEditDialog = false; //弹框loading
            this.formData = res.data.yjQmpMsWrokorderExecutionreport;
            this.getUser(this.formData.fOrderreceiptid);
            this.formData.fCcpeoples = this.formData.fCcpeoples.join(",");
            if (this.Sign == "签收") {
              if (
                this.formData.fSignname == "" ||
                this.formData.fSignname == null ||
                this.formData.fSignid == "" ||
                this.formData.fSignid == null
              ) {
                this.formData.fSignname = this.userInfo.realName; //签收人
                this.formData.fSignid = this.userInfo.userId;
              }
              if (
                this.formData.fSigndates == "" ||
                this.formData.fSigndates == null
              ) {
                this.formData.fSigndates = this.timeYMD; //签收日期
              }
              this.formData.fSignresult = "已签收";
            } else {
              if (
                this.formData.fIssuername == "" ||
                this.formData.fIssuername == null ||
                this.formData.fIssuerid == "" ||
                this.formData.fIssuerid == null
              ) {
                this.formData.fIssuername = this.userInfo.realName; // 签发人
                this.formData.fIssuerid = this.userInfo.userId;
              }
              if (
                this.formData.fIssuerdates == "" ||
                this.formData.fIssuerdates == null
              ) {
                this.formData.fIssuerdates = this.timeYMD; //签发日期
              }
              if (
                this.formData.fReplydates == "" ||
                this.formData.fReplydates == null
              ) {
                this.formData.fReplydates = this.timeYMD; // 要求回复日期
              }
              if (
                this.formData.fInformantdates == "" ||
                this.formData.fInformantdates == null
              ) {
                this.formData.fInformantdates = this.timeYMD; // 填报日期
              }
              if (
                this.formData.fInformantname == "" ||
                this.formData.fInformantname == null ||
                this.formData.fInformantid == "" ||
                this.formData.fInformantid == null
              ) {
                this.formData.fInformantname = this.userInfo.realName; //填报人
                this.formData.fInformantid = this.userInfo.userId;
              }
            }

            if (this.formData.fCcpeoples != []) {
              this.CcpeoplesUserList = this.formData.fCcpeoples;
            }

            this.fSourcefileList = res.data.fOrderfilelist; //本次检查相关资料
          } else {
            this.loadingEditDialog = false; //弹框loading
            return this.$message.error(res.msg);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },

    // 保存
    yj_saveForm(num) {
      if (num == 0) {
        this.getUserList.map((item) => {
          if (this.formData.fSignsubname == item.value) {
            this.formData.fSignsubid = item.id;
          }
        });

        if (this.$refs.publicForm.submitForm()) {
          this.saveData = {
            fId: this.formData.fId, //传此表示修改
            userId: this.userInfo.userId, //当前登录人id
            userName: this.userInfo.realName, // 当前登录人名称
            fProjectname: this.userInfo.projectName, // 当前登录人项目名称
            fProjectid: this.userInfo.projectId, // 当前登录人项目ID
            fCompanyname: this.userInfo.companyName, // 当前登录人标段名称
            fCompanyid: this.userInfo.companyId, // 当前登录人标段ID
            fOrdertype: this.formData.fOrdertype, // 指令单类型
            fOrderissuingname: this.formData.fOrderissuingname, // 指令单签发单位
            fOrderissuingid: this.formData.fOrderissuingid, // 指令单签发单位id
            fOrdernumber: this.formData.fOrdernumber, // 指令单编号
            fOrderreceiptname: this.formData.fOrderreceiptname, // 指令单签收单位
            fOrderreceiptid: this.formData.fOrderreceiptid, // 指令单签收单位id
            fIssuername: this.formData.fIssuername, // 签发人姓名
            fIssuerid: this.formData.fIssuerid, // 签发人
            fIssuerdates: this.formData.fIssuerdates, // 签发日期
            fQualitygridclass: this.formData.fQualitygridclass, // 涉及工程质量网格
            fQualitygridtype: this.formData.fQualitygridtype, // 涉及工程质量网格
            fOrederdetail: this.formData.fOrederdetail, // 工作指令内容
            fReplydates: this.formData.fReplydates, // 要求回复日期
            fOrderfile: this.formData.fOrderfile, // 附件资料
            fSignsubname: this.formData.fSignsubname, // 指定签收人姓名
            fSignsubid: this.formData.fSignsubid, // 指定签收人id
            fCcpeoples: this.userList, //抄送人姓名集合
            fCcpeopleids: this.userListId,
            fInformantname: this.formData.fInformantname, // 填报人姓名
            fInformantid: this.formData.fInformantid, // 填报人id
            fInformantdates: this.formData.fInformantdates, // 填报日期
            recordfiles: this.recordfiles, // 删除文件id集合

            // fQualitygridclassid: this.formData.fQualitygridclassid, // 涉及工程质量网格id
          };
          saveWorkOrder(this.saveData)
            .then((res) => {
              if (res.errcode == 0) {
                this.yj_searchForm(this.getList);
                this.dialogEditVisible = false;
                this.$message.success("新增成功");
              } else {
                this.$message.error(res.msg);
                console.log("接口报错");
              }
            })
            .catch((error) => {
              console.log(error);
            });
        } else {
          console.log("error");
        }
      } else if (num == 1) {
        if (this.$refs.publicForm0.submitForm()) {
          var saveData1 = {
            fId: this.formData.fId, //传此表示修改
            fSignresult: this.formData.fSignresult, //签收结果 未签收、已签收
            fSigndates: this.formData.fSigndates, //签收时间
            fSignname: this.userInfo.realName, //签收人姓名
            fSignid: this.userInfo.userId, //签收人id
            fSignmessage: this.formData.fSignmessage, //签收说明
          };
          saveWorkOrderBySign(saveData1)
            .then((res) => {
              if (res.errcode == 0) {
                this.yj_searchForm(this.getList);
                this.dialogEditVisible = false;
                this.$message.success("签收成功");
              } else {
                this.$message.error(res.msg);
                console.log("签收接口报错");
              }
            })
            .catch((error) => {
              console.log(error, "签收接口报错");
            });
        } else {
          console.log("error");
        }
      } else if (num == 3) {
        this.FromShow[10].options = [];
        // 机构树保存
        this.formData.fOrderreceiptname = this.showTreeData.fShortname; // 指令单签收单位------弹出框选机构树
        this.formData.fOrderreceiptid = this.showTreeData.fCompanyid; // 指令单签收单位idq
        this.dialogEditVisibles = false;

        this.getUser(this.formData.fOrderreceiptid);
      }
    },
    // 调人员
    getUser(id) {
      getBaseDepartmentUser({ fCompanyid: id })
        .then((res) => {
          if (res.errcode == 0) {
            var getUser = {
              value: "",
              label: "",
            };
            this.getUserInitialList = []; //人员列表初始值
            this.getUserList = []; //人员列表过滤后

            res.data.childList.map((v) => {
              if (v.personList != undefined) {
                v.personList.map((item) => {
                  this.getUserInitialList.push(item);
                });
              }
            });

            if (this.propText == "fOrderreceiptname") {
              this.getUserInitialList.map((item) => {
                getUser = {
                  value: item.fRealname,
                  label: item.fRealname,
                  id: item.fUserid,
                };
                this.getUserList.push(getUser);
              });

              console.log("getUserList", this.getUserList);

              this.FromShow[10].options = this.getUserList;
            }
          } else {
            this.$message.error(res.msg);
            console.log("部门管理-查询部门列表以及下属人员,接口报错");
          }
        })
        .catch((error) => {
          console.log("部门管理-查询部门列表以及下属人员", error.msg);
        });
    },
    //签发
    SubmitText(id) {
      if (id != "" && id != null) {
        if (this.row.fstatus == "签发中") {
          this.$confirm("是否继续签发?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              this.loading = true;
              commitWorkOrderExecutionReport({
                fId: id,
                userId: this.userInfo.userId,
                userName: this.userInfo.realName,
              })
                .then((res) => {
                  if (res.errcode == 0) {
                    this.loading = false;
                    this.yj_searchForm(this.getList);
                    this.$message.success("签发成功");
                  } else {
                    this.$message.error("签发失败", res.msg);
                    this.loading = false;
                  }
                })
                .catch(() => {
                  console.log("签发失败");
                  this.loading = false;
                });
            })
            .catch(() => {
              this.$message("取消签发");
            });
        } else {
          return this.$message.error("请选择信息状态为‘签发中’的数据");
        }
      } else {
        return this.$message.error("请先选择需要签发的数据");
      }
    },
    // 删除
    rowDelete(id) {
      if (id != "" && id != null) {
        if (this.row.fstatus == "签发中") {
          this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              this.loading = true;
              deleteWorkOrderExecutionReport({ fId: id })
                .then((res) => {
                  if (res.errcode == 0) {
                    this.loading = false;
                    this.yj_searchForm(this.getList);
                    this.$message.success("删除成功");
                  } else {
                    this.$message.error("删除失败", res.msg);
                    this.loading = false;
                  }
                })
                .catch(() => {
                  console.log("删除失败");
                  this.loading = false;
                });
            })
            .catch(() => {
              this.$message("取消删除");
            });
        } else {
          return this.$message.error("请选择信息状态为‘签发中’的数据");
        }
      } else {
        return this.$message.error("请先选择需要删除的数据");
      }
    },
    // 获取页面容器高度
    getHeight() {
      var h = document.documentElement.clientHeight; //获取页面可见高度
      this.dialogHeight = h * 0.36 + "px";
    },
    // 树结构
    getTree() {
      this.treeText.companyId = this.userInfo.companyId;
      this.treeText.userId = this.userInfo.userId;
      this.dialogEditVisibles = true;
      this.loadingEditDialogs = true;
      getUserCompanyTreeList(this.treeText)
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);
            this.loadingEditDialogs = false;
          } else {
            this.$message.error(res.msg);
            this.loadingEditDialogs = false;
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },
    // 点击机构树
    getRowInfos(data) {
      this.showTreeData = data; //顶部显示机构名
    },
    // 点击当前行变色
    rowChangeColor(val) {
      return val;
    },
    // 点击查看
    yj_viewForm(row, label) {
      this.row = row;
      this.fId = row.fId;
      if (label == "指令单编号") {
        this.editText(this.fId);
      }
    },
    // 查看
    editText(id) {
      this.FromShow = this.FromShowLook;
      this.putAway = this.putAwayLook;
      this.dialogTitle = "查看";
      this.Sign = "查看";
      this.btnShow = false;
      if (id != "" && id != null) {
        this.loadingEditDialog = true; //弹框loading
        this.dialogEditVisible = true;
        getWorkOrderExecutionReportByFid({ fId: id })
          .then((res) => {
            if (res.errcode == 0) {
              var that = this;
              that.loadingEditDialog = false;
              this.formData = res.data.yjQmpMsWrokorderExecutionreport;
              this.fSourcefileList = res.data.fOrderfilelist; //本次检查相关资料
            } else {
              this.$message.error("查看", res.msg);
              this.loadingEditDialog = false;
            }
          })
          .catch(() => {
            console.log("查看---详情接口报错");
            this.loadingEditDialog = false;
          });
      } else {
        return this.$message.error("请先选择需要查看的数据");
      }
    },
    getData() {
      var time = new Date();
      const y = time.getFullYear();
      const m = (time.getMonth() + 1 + "").padStart(2, "0");
      const d = (time.getDate() + "").padStart(2, "0");
      this.timeYMD = `${y}-${m}-${d}`;
    },
    // 点击当前
    rowChange(val) {
      this.row = val;
      this.fId = val.fId;
    },
    // 刪除
    delteFile(file) {
      for (let index = 0; index < this.fSourcefileList.length; index++) {
        if (file.uid == this.fSourcefileList[index].uid) {
          if (this.fSourcefileList[index].atta == undefined) {
            this.recordfiles.push({
              fId: this.fSourcefileList[index].fId,
            });
          } else {
            this.recordfiles.push({
              fId: this.fSourcefileList[index].atta.fId,
            });
          }
          this.fSourcefileList.splice(index, 1);
        }
      }
    },
    inputChange(value, index, prop) {
      // console.log("inputChange", value, index, prop);
      return value, index, prop;
    },
    inputFocus(index, prop) {
      // console.log(index, prop);
      this.propText = prop;
      if (prop == "fOrderreceiptname") {
        this.getTree();
      } else if (prop == "fCcpeoples") {
        if (
          this.formData.fOrderissuingid == null ||
          this.formData.fOrderissuingid == ""
        ) {
          this.$message.error("请先填写指令单签发单位");
        } else {
          if (this.dialogTitle != "新增") {
            this.newData = [];
            this.checkboxGroup1 = [];
            this.getUserInitialList.map((item) => {
              this.formData.fCcpeopleids.map((v) => {
                if (item.fUserid == v) {
                  this.newData.push(item);
                }
              });
            });
            this.allUserInfo = this.allUserInfo.concat(this.newData);

            this.newData.map((item) => {
              this.checkboxGroup1.push(item.fUserid);
            });
          }

          this.candidate = "选择抄送人";
          this.treeText.companyId = this.formData.fOrderissuingid;
          this.treeText.userId = this.userInfo.userId;
          this.getBaseCompanyList(this.treeText);
        }
      }
    },
    selectChange(value, index, prop) {
      if (prop == "fQualitygridclass") {
        // 涉及质量网格类别 联动
        this.FromShow[7].placeholder = "请先选择涉及质量网格类别";
        if (value == "生产场站质量网格") {
          this.formData.fQualitygridtype = "";
          this.FromShow[7].placeholder = "请选择";
          this.FromShow[7].options = [
            {
              value: "混凝土拌合站",
              label: "混凝土拌合站",
            },
            {
              value: "水稳料拌合站",
              label: "水稳料拌合站",
            },
            {
              value: "沥青料拌合站",
              label: "沥青料拌合站",
            },
            {
              value: "钢筋加工场",
              label: "钢筋加工场",
            },
            {
              value: "梁板预制场",
              label: "梁板预制场",
            },
            {
              value: "碎石材料加工厂",
              label: "碎石材料加工厂",
            },
            {
              value: "小型预制构件厂",
              label: "小型预制构件厂",
            },
          ];
        } else if (value == "工程实体质量网格") {
          this.formData.fQualitygridtype = "";
          this.FromShow[7].placeholder = "请选择";
          this.FromShow[7].options = [
            {
              value: "路基土石方",
              label: "路基土石方",
            },
            {
              value: "路面工程",
              label: "路面工程",
            },
            {
              value: "桥梁工程",
              label: "桥梁工程",
            },
            {
              value: "隧道工程",
              label: "隧道工程",
            },
            {
              value: "涵洞工程",
              label: "涵洞工程",
            },
            {
              value: "防护排水",
              label: "防护排水",
            },
            {
              value: "交安工程",
              label: "交安工程",
            },
            {
              value: "管道工程",
              label: "管道工程",
            },
            {
              value: "房建工程",
              label: "房建工程",
            },
            {
              value: "绿化工程",
              label: "绿化工程",
            },
          ];
        } else if (value == "/") {
          this.formData.fQualitygridtype = "/";
          this.FromShow[7].options = [];
        }
      }

      if (prop == "fCcpeoples") {
        // 抄送人
        this.CcpeoplesUserList = [];
        value.map((v) => {
          if (v.label != undefined) {
            this.CcpeoplesUserList.push(v.label);
          } else {
            this.CcpeoplesUserList.push(v);
          }
        });
      }
    },
    // 树选人
    // 树结构
    getBaseCompanyList(data) {
      // this.personList = [];
      // this.departmentList = [];
      this.dialogEditVisibleTree = true;
      this.loadingEditDialogTree = true;
      getUserCompanyTreeList(data)
        .then((res) => {
          this.loadingEditDialogTree = false;
          if (res.errcode == 0) {
            this.companyTreeData = res.data.userCompanyTreeList;
            this.companyInfo = this.tranListToTreeData(
              res.data.userCompanyTreeList
            );
          } else {
            this.$message.error("获取组织机构单位", res.msg);
          }
        })
        .catch((error) => {
          console.log("获取组织机构单位,接口报错", error);
        });
    },
    tranListToTreeData(data) {
      let result = [];
      if (!Array.isArray(data)) {
        return result;
      }
      // 清除已存在的数据  重新赋值
      data.forEach((item) => {
        delete item.children;
      });

      let map = {};
      data.forEach((item) => {
        map[item.fCompanyid] = item;
      });

      data.forEach((item) => {
        let parent = map[item.fParentid];
        if (parent) {
          (parent.children || (parent.children = [])).push(item);
        } else {
          result.push(item);
        }
      });
      return result;
    },
    //根据树  调部门
    selectCompany(e) {
      this.getBaseDepartmentUser(e.fCompanyid);
    },
    // 部门管理-查询部门列表以及下属人员
    getBaseDepartmentUser(id) {
      getBaseDepartmentUser({ fCompanyid: id })
        .then((res) => {
          if (res.errcode == 0) {
            this.departmentList = res.data.childList;
          } else {
            this.$message.error("部门管理-查询部门列表以及下属人员", res.msg);
          }
        })
        .catch((error) => {
          console.log("部门管理-查询部门列表以及下属人员,接口报错", error);
        });
    },
    // 选择部门
    seletDepartment(e) {
      this.num = e.fDepartmentId;
      this.personList = [];
      let obj = {};
      // let reduce = [];
      this.personList = e.personList.reduce(function (item, next) {
        //item为没有重复id的数组，next为当前对象
        obj[next.fUserid] ? "" : (obj[next.fUserid] = true && item.push(next));
        return item;
      }, []);
    },
    selectRealname(e, data) {
      this.allUserInfo = this.allUserInfo.concat(data);
      let obj = {};
      let reduce = [];
      reduce = this.allUserInfo.reduce((item, next) => {
        //item为没有重复id的数组，next为当前对象
        obj[next.fUserid] ? "" : (obj[next.fUserid] = true && item.push(next));
        return item;
      }, []);
      this.newData = [];
      reduce.map((item) => {
        this.checkboxGroup1.map((i) => {
          if (item.fUserid == i) {
            this.newData.push(item);
          }
        });
      });
    },
    // 删除用户
    deteleUser(id) {
      this.newData = this.newData.filter((item) => {
        return item.fUserid != id;
      });
      this.checkboxGroup1 = this.checkboxGroup1.filter((item) => {
        return item != id;
      });
    },
    // 保存
    submitMember() {
      if (this.propText == "fCcpeoples") {
        this.userList = [];
        this.userListId = [];
        this.newData.map((item) => {
          this.userList.push(item.fRealname);
          this.userListId.push(item.fUserid);
        });

        this.formData.fCcpeoples = this.userList.join(","); //抄送人姓名集合
      }
      this.dialogEditVisibleTree = false;
    },
    // 树选人
    // 多选方法
    selectionChange() {},
    // 排序方法
    sortChange() {},
  },
};
</script>

<style scoped lang="less">
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

.baseTitle {
  /* border: 1px solid #0c204d; */
  border-bottom: 1px solid #0c204d;
  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
}
/* 弹框 */
.publicForm {
  display: flex;
}
.publicForm .mouldForm /deep/ .el-form-item__content {
  margin-left: 120px !important;
}
.publicFormBox {
  width: 50%;
  height: 100%;
}
.closure /deep/ .el-input__suffix {
  left: 91%;
}
/* 树选人 */

.addMemberCheckBox {
  display: flex;

  .addMemberCheckTree {
    width: 30%;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(221, 221, 221, 1);
    box-sizing: border-box;

    .companyBox {
      height: 70%;
      box-sizing: border-box;
      overflow-y: auto;
    }

    .departmentBox {
      height: 30%;
      border-top: 0.5px solid rgba(221, 221, 221, 1);
      /* border: 1px solid red; */
      display: flex;
      flex-wrap: wrap;
      align-content: flex-start;
      overflow: hidden;
      overflow-y: auto;

      .departmentTitle {
        width: 77px;
        text-align: center;
        height: 40px;
        margin: 5px;
        // border: 1px solid green;
        border-radius: 8px;
        background: #d4daea;
        overflow: hidden;

        a {
          width: 100%;
          height: 100%;
          display: block;
          text-decoration: none;
        }
      }
    }
  }

  .selectMemberLeft {
    display: flex;
    align-items: center;
  }

  .addMemberCheckLeft {
    width: 52%;
    padding: 0 0 0 20px;
    border-top: 1px solid rgba(221, 221, 221, 1);
    border-bottom: 1px solid rgba(221, 221, 221, 1);
    border-right: 1px solid rgba(221, 221, 221, 1);

    .addMemberCheck {
      width: 150px;
      height: 64px;
      border-radius: 2px;
      display: flex;
      align-items: center;
      position: absolute;
      top: 0;
      left: 0;
    }
  }
}

.newlyAdded_btns {
  height: 8%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.addMemberCheck .MemberIcon {
  height: 62px;
  width: 64px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(241, 241, 241, 1);
}

.MemberIcon img {
  width: 37.81px;
  height: 39.38px;
  border-radius: 50%;
}

.MemberDetailInfos {
  position: relative;
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;

  .name {
    color: rgba(51, 51, 51, 1);
    font-size: 12px;
    height: 20px;
    line-height: 20px;
  }

  .hostName {
    color: rgba(128, 125, 125, 1);
    font-size: 12px;
    height: 20px;
    line-height: 20px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.MemberIcon .name {
  color: rgba(51, 51, 51, 1);
  font-size: 12px;
  height: 20px;
  line-height: 20px;
}

.MemberIcon .hostName {
  color: rgba(128, 125, 125, 1);
  font-size: 12px;
  height: 20px;
  line-height: 20px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.activetext {
  color: rgba(197, 227, 255, 1);
  background: #2b5a9d;
}
.addMemberCheckBox .selectPerson {
  width: 18%;
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(221, 221, 221, 1);
  margin-left: 15px;
  box-sizing: border-box;

  .selectPersonTitle {
    height: 28px;
    line-height: 28px;
    text-align: center;
    background: rgba(241, 241, 241, 1);
    border-bottom: 1px solid rgba(221, 221, 221, 1);
    color: rgba(128, 125, 125, 1);
    font-size: 12px;
  }

  .selectPersonData {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;

    .selectPersonDataBox {
      width: 165px;
      height: 72px;
      border-radius: 2px;
      border: 1px solid rgba(222, 222, 222, 1);
      margin: 8px 0;
      display: flex;
      position: relative;

      .MemberIcon {
        height: 100%;
        width: 64px;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-right: 8px;
        background: rgba(241, 241, 241, 1);

        img {
          width: 37.81px;
          height: 39.38px;
          border-radius: 50%;
        }
      }

      .MemberDetailInfo1 {
        position: relative;
        flex: 1;
        height: 100%;
        padding: 14px 0;
        overflow: hidden;

        .name {
          color: rgba(51, 51, 51, 1);
          font-size: 12px;
          height: 20px;
          line-height: 5px;
          white-space: nowrap;
        }

        .hostName {
          color: rgba(128, 125, 125, 1);
          font-size: 12px;
          height: 20px;
          line-height: 10px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
    }
  }
}
.MemberDetailInfo::after {
  position: absolute;
  width: 30px;
  height: 30px;
  display: block;
  background: url("../../../../../assets/img/organization/yes.png") no-repeat;
  background-size: 100% 100%;
  right: 0;
  top: 0;
}

.deleteUser {
  position: absolute;
  width: 22px;
  height: 22px;
  display: block;
  background: url("../../../../../assets/img/organization/no.png") no-repeat;
  background-size: 100% 100%;
  right: 0;
  top: 0;
}

.samllDialogs {
  display: flex;
  margin: 0 20px;
  padding-top: 50px;
  .treeModule {
    flex: 1;
  }
}

/* 树选人 */

/* 弹框 */
</style>